package com.example.homeworkmanagement.controller;


import com.example.homeworkmanagement.pojo.Majors;
import com.example.homeworkmanagement.service.MajorsService;
import com.example.homeworkmanagement.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 拒绝加班
 * @since 2025-05-25
 */
@RestController
@RequestMapping("/majors")
@Api(tags = "专业信息管理接口")
@CrossOrigin
public class MajorsController {
    @Autowired
    private MajorsService majorsService;
    /**
     * 获取所有专业列表
     */
    @GetMapping("/getMajorsList")
    @ApiOperation(value = "获取所有专业列表")
    public ResultVO<List<Majors>> getMajorsList() {
        return majorsService.getMajorList();
    }

    /**
     * 根据部门获取专业列表
     */
    @GetMapping("/getMajorListByDepartment")
    @ApiOperation(value = "根据部门获取专业列表")
    @ApiImplicitParam(name = "department", value = "部门名称", required = true, dataType = "String")
    public ResultVO<List<Majors>> getMajorListByDepartment( String department) {
        return majorsService.getMajorListByDepartment(department);
    }

    /**
     * 添加专业
     */
    @PostMapping("/addMajor")
    @ApiOperation(value = "添加专业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "major", value = "专业名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "department", value = "学院名称", required = true, dataType = "String")
    })
    public ResultVO<Majors> addMajor(Majors major) {
        return majorsService.addMajor(major);
    }

    /**
     * 更新专业信息
     */
    @PutMapping("/update")
    @ApiOperation(value = "更新专业信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "majorId", value = "专业id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "major", value = "专业名称", dataType = "String"),
            @ApiImplicitParam(name = "department", value = "学院名称", dataType = "String")
    })
    public ResultVO<Majors> updateMajor(Majors major) {
        return majorsService.updateMajor(major);
    }


    /**
     * 删除专业
     */
    @DeleteMapping("/deleteMajor")
    @ApiOperation(value = "删除专业")
    @ApiImplicitParam(name = "majorId", value = "专业id", required = true, dataType = "String")
    public ResultVO<Majors> deleteMajor(String majorId) {
        return majorsService.deleteMajor(majorId);
    }
}
